﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;

using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;


public partial class UpdateMutilDataSQL : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

        if (!Page.IsPostBack)
        {
            DataTable dtNews = get_ALL_NEWS().Tables[0];

            for (int i = 0; i < dtNews.Rows.Count; i++)
            {
                //Response.Write(dtNews.Rows[i]["IMAGE"].ToString() + "</br>");

                int iID = int.Parse(dtNews.Rows[i]["ID"].ToString());

                string strImg = dtNews.Rows[i]["IMAGE"].ToString();
                strImg = strImg.Replace("http://truongdaynghethanhxuan.edu.vn/", "http://dientudienlanhthanhxuan.com/");
                BusLogic.News.update_LINK_IMAGE_NEWS(iID, strImg);
            }
        }

    }

    public static DataSet get_ALL_NEWS()
    {
        DataSet retData = new DataSet();
        String connString = ConfigurationManager.ConnectionStrings["DBDIENLANH"].ConnectionString;

        using (SqlConnection Conn = new SqlConnection(connString))
        {
            try
            {
                String strCommandText;
                SqlCommand objCommand;

                strCommandText = @"SELECT * FROM NEWS";

                objCommand = new SqlCommand(strCommandText, Conn);
                objCommand.CommandType = CommandType.Text;

                SqlDataAdapter adap = new SqlDataAdapter(objCommand);
                Conn.Open();
                adap.Fill(retData, "Table");
                Conn.Close();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (Conn.State == ConnectionState.Open)
                    Conn.Close();
            }
        }
        return retData;
    }
}
